/**
 * 组件库
 */
import 'package:flutter_benchu/utils/commonPkg.dart';
// 保存图片到相册
import 'package:image_picker_saver/image_picker_saver.dart';

// https://docs.getwidget.dev/gf-progress-bar/#circular-progress-bar

class GetwidgetDemoPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _GetwidgetDemoPageState();
}

class _GetwidgetDemoPageState extends State<GetwidgetDemoPage> {
  @override
  Widget build(BuildContext context) {

    final painter = QrPainter(
      data: '1234567890',
      version: QrVersions.auto,
      gapless: true,
      errorCorrectionLevel: QrErrorCorrectLevel.L,
      color: const Color(0xFF000000),
    );

    return Scaffold(
      appBar: AppBar(title: Text('组件展示')),
      body: Container(
        child: Column(
          children: [
            GFButton(
              onPressed: () {},
              text: "primary",
            ),
            GFToggle(
              onChanged: (val) {},
              value: null,
            ),
            GFToggle(
              onChanged: (val) {},
              value: null,
            ),
            GFProgressBar(
                percentage: 0.9,
                width: 100,
                radius: 90,
                backgroundColor: Colors.black26,
                progressBarColor: GFColors.DANGER),
            GFProgressBar(
                percentage: 0.9,
                backgroundColor: Colors.black26,
                progressBarColor: GFColors.DANGER),
            GFProgressBar(
              percentage: 0.5,
              lineHeight: 20,
              child: const Padding(
                padding: EdgeInsets.only(right: 5),
                child: Text(
                  '50%',
                  textAlign: TextAlign.end,
                  style: TextStyle(fontSize: 16, color: Colors.white),
                ),
              ),
              backgroundColor: Colors.black26,
              progressBarColor: GFColors.WARNING,
            ),
            GFLoader(),
            GFToast(
              text: 'This item already has the label “travel”',
              button: GFButton(
                onPressed: () {},
                text: 'Close',
                type: GFButtonType.transparent,
              ),
              autoDismiss: false,
            ),
            SpinKitRotatingCircle(
              color: Colors.indigoAccent,
              size: 20.sp,
            ),
            SpinKitChasingDots(
              color: Colors.red,
              size: 20.sp,
            ),
            SpinKitThreeBounce(
              color: Colors.deepPurple,
              size: 20.sp,
            ),
            Badge(
              badgeContent: Text('3'),
              child: Icon(Icons.zoom_in_rounded),
            ),
            CustomPaint(
              painter: painter,
              size: Size(120.w, 120.w),
            ),
            GFButton(
              onPressed: () async {
                // 保存相片到本地
                var data = await painter.toImageData(400);
                ImagePickerSaver.saveFile( fileData:data.buffer.asUint8List());
              },
              text: "保存图片",
            ),




          ],
        ),
      ),
    );
  }
}
